package org.example.core.utils;


import org.example.core.enums.ValidatorType;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 校验工具
 * @author Calvin
 */
public class DataValidator {

    public static boolean isValidEmail(String email) {
        Pattern pattern = Pattern.compile(ValidatorType.EMAIL_REGEX.getDesc(), Pattern.CASE_INSENSITIVE);
        Matcher matcher = pattern.matcher(email);
        return matcher.matches();
    }

    public static boolean isValidPhone(String phone) {
        Pattern pattern = Pattern.compile(ValidatorType.PHONE_REGEX.getDesc(), Pattern.CASE_INSENSITIVE);
        Matcher matcher = pattern.matcher(phone);
        return matcher.find();
    }

    public static boolean isValidMorePhone(String phoneNumbers) {
        boolean flag =true;
        String[] numbers = phoneNumbers.split(",");
        Pattern pattern = Pattern.compile(ValidatorType.MORE_PHONE_REGEX.getDesc(), Pattern.CASE_INSENSITIVE);
        for (String number : numbers) {
            Matcher matcher = pattern.matcher(number);
            if (!matcher.matches()) {
                flag=false;
            }
        }
        return flag;

    }

    public static boolean isValidUrl(String url) {
        Pattern pattern = Pattern.compile(ValidatorType.URL_REGEX.getDesc(), Pattern.CASE_INSENSITIVE);
        Matcher matcher = pattern.matcher(url);
        return matcher.matches();
    }

    public static void main(String[] args) {
/*        String url = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=65298cd8-4f5e-4766-b862-b3a6eb713c0e";
        String url1 ="https://cube-tech.zhonganinfo.com/ship/configCenter/1326/info/za-data-notice/1326/6087/edit";
        System.out.println(isValidUrl(url));
        String email = "example@qq.com";
        System.out.println(isValidEmail(email));
        System.out.println(isValidUrl(url1)); // true*/


            String phoneNumbers = "18309864917,13017992932";

        System.out.println(isValidMorePhone(phoneNumbers));

            String regex = "^1[3-9]\\d{9}$";
            Pattern pattern = Pattern.compile(regex);
            String[] numbers = phoneNumbers.split(",");
            for (String number : numbers) {
                Matcher matcher = pattern.matcher(number);
                if (matcher.matches()) {
                    System.out.println(number + " 是合法的手机号码");
                } else {
                    System.out.println(number + " 不是合法的手机号码");
                }
            }
    }



}
